package com.jhws.sys.appUser.api;

import com.jhws.business.comm.bo.TblBuildingDimBo;
import com.jhws.business.comm.bo.TblCommDimBo;
import com.jhws.business.device.bo.DeviceConstant;
import com.jhws.business.face.bo.FaceInfo;
import com.jhws.business.face.service.FaceService;
import com.jhws.business.owner.bo.OwnerDataUpdate;
import com.jhws.business.owner.bo.OwnerConstant;
import com.jhws.business.owner.bo.TblOwnerDimBo;
import com.jhws.business.owner.service.ITblOwnerDimService;
import com.jhws.common.base.bo.Global;
import com.jhws.common.base.bo.JsonRespData;
import com.jhws.business.device.bo.UserDevice;
import com.jhws.sys.appUser.bo.TblSipAcountDimBo;
import com.jhws.sys.appUser.bo.UserInfoV2;
import com.jhws.core.dataUpdate.bo.DataUpdateObject;
import com.jhws.core.dataUpdate.bo.DataUpdateParam;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import com.jhws.core.exception.BizException;
import com.jhws.business.comm.service.ITblBuildingDimService;
import com.jhws.business.comm.service.ITblCommDimService;
import com.jhws.business.advertisement.service.ITblNoticeDimService;
import com.jhws.sys.appUser.service.ITblSipAcountDimService;
import com.jhws.sys.appUser.bo.TblSipAcountBindings;
import com.jhws.util.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(("/v2/appUser"))
public class appUserApiV2 extends AppUserApiV1 {
    @Resource
    private ITblCommDimService ICommService;
    @Resource
    private ITblSipAcountDimService ISipAcountService;
    @Resource
    private RedisTemplate stringTemplate;
    @Resource
    private ITblNoticeDimService noticeDimService;
    @Resource
    private ITblOwnerDimService IOwnerService;
    @Resource
    private DataUpdateService dataUpdateService;
    @Resource
    private FaceService faceService;
    @Resource
    protected ITblBuildingDimService buildingDimService;

    @Override
    @RequestMapping({"anon/modifyPassword", "modifyPassword"})
    public void updatePassword(String findPwd, String username, String oldPassword, String newPassword) {
        // TODO Auto-generated method stub
        super.updatePassword(findPwd, username, oldPassword, newPassword);
    }

    @Resource
    private ITblBuildingDimService IBuildingService;
    private final String[] numberToEnglish = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

    @Override
    @RequestMapping("anon/autoGeneratedAccount")
    public JsonRespData autoGeneratedAccount() {
        // TODO Auto-generated method stub
        return super.autoGeneratedAccount();
    }

    @Override
    @RequestMapping({"anon/registerAccount", "registerAccount"})
    public JsonRespData registerAccount(String username, String password) {
        // TODO Auto-generated method stub
        return super.registerAccount(username, password);
    }

    @Override
    public JsonRespData getUserInfoList(String username) throws Exception {

        // TODO Auto-generated method stub
        List<TblSipAcountBindings> list = ITblSipAcountDimService.getBindingsByUser(username);
        if (list == null || list.size() <= 0) {
            throw new BizException("-1", "getAllBindingList", "还没有绑定任何物业！");
        }

        // 是否保存过别墅类型，别墅只保存一条记录
        boolean isSaveVILLA_TYPE = false;
        String villaBinding = null;
        UserInfoV2 userInfoV2;
        List<UserInfoV2> uList = new ArrayList<>();
        ACLinkedMultiValueMap<String, UserDevice> acLinkedMultiValueMap = new ACLinkedMultiValueMap<String, UserDevice>();
        for (TblSipAcountBindings tblSipAcountBindings : list) {
            String sipNum = tblSipAcountBindings.getBinding();
            int devicesType = AccountsUtils.devicesType(sipNum);

            if (devicesType == DeviceConstant.WALL_TYPE) {
                String dispName = "围墙机-" + sipNum.substring(sipNum.length() - 1, sipNum.length());
                acLinkedMultiValueMap.add(sipNum.substring(0, 4), new UserDevice(sipNum, dispName));
            } else if (devicesType == DeviceConstant.OUTDOOR_TYPE) {
                String dispName = AccountsUtils.getUnitInfo(sipNum) + ":门口机-"
                        + sipNum.substring(sipNum.length() - 1, sipNum.length());
                acLinkedMultiValueMap.add(sipNum.substring(0, 4), new UserDevice(sipNum, dispName));
            } else if (devicesType == DeviceConstant.VILLA_TYPE) {
                if (!isSaveVILLA_TYPE) {
                    isSaveVILLA_TYPE = true;
                    villaBinding = tblSipAcountBindings.getBinding();
                    uList.add(
                            new UserInfoV2(2, villaBinding, "0000", "别墅", OwnerConstant.ROLE_VILLA_TYPE));
                }
                acLinkedMultiValueMap.add(villaBinding,
                        new UserDevice(sipNum, "别墅机-" + sipNum.substring(sipNum.length() - 1, sipNum.length())));
            } else if (devicesType == DeviceConstant.INDOOR_TYPE) {
                TblOwnerDimBo tblOwnerDimBo = ITblOwnerDimService.findTblOwnerDimByMobOrRoomInfo(username,
                        tblSipAcountBindings.getBinding());
                String commCode = tblSipAcountBindings.getBinding().substring(0, 4);
                TblCommDimBo tblCommDimBo = ITblCommDimService.findTblCommDimById(commCode);
                if (tblOwnerDimBo != null) {
                    if (tblOwnerDimBo.getApplyType() == OwnerConstant.OWNER_TYPE || tblOwnerDimBo.getApplyType() == OwnerConstant.OWNER_TYPE_RENTER) {
                        userInfoV2 = new UserInfoV2(OwnerConstant.OWNER_TYPE, tblSipAcountBindings.getBinding(),
                                tblOwnerDimBo.getCommCode(), tblOwnerDimBo.getCommName(), OwnerConstant.ROLE_OWNER_TYPE);
                    } else {
                        userInfoV2 = new UserInfoV2(tblOwnerDimBo.getApplyType(), tblSipAcountBindings.getBinding(),
                                tblOwnerDimBo.getCommCode(), tblOwnerDimBo.getCommName(), OwnerConstant.ROLE_FAMILY_TYPE);
                    }

                    uList.add(userInfoV2);
                    List<TblSipAcountBindings> bList = ISipAcountService.genDefaultSipUnlockMonitorBindingList(username,
                            tblSipAcountBindings.getBinding());
                    for (TblSipAcountBindings binding : bList) {
                        String name = binding.getBinding();
                        if (AccountsUtils.devicesType(name) == DeviceConstant.WALL_TYPE)
                            name = commUtil.getGateDevAliasName(name, tblCommDimBo.getGateDevAliasName());
                        else if (AccountsUtils.devicesType(name) == DeviceConstant.OUTDOOR_TYPE)
                            name = "门口机-" + name.substring(name.length() - 1);
                        acLinkedMultiValueMap.add(userInfoV2.getBindingRoom(), new UserDevice(binding.getBinding(), name));
                    }

                }
            } else if (devicesType == DeviceConstant.MANAGE_TYPE) {
                String commCode = tblSipAcountBindings.getBinding().substring(0, 4);
                TblCommDimBo tblCommDimBo = ITblCommDimService.findTblCommDimById(commCode);
                if (tblCommDimBo != null) {
                    userInfoV2 = new UserInfoV2(0, tblSipAcountBindings.getBinding(), tblCommDimBo.getCommCode(),
                            tblCommDimBo.getCommName(), OwnerConstant.ROLE_MANAGER_TYPE);
                    uList.add(userInfoV2);
                }
            }
        }

        for (UserInfoV2 uInfoV2 : uList) {
            if (acLinkedMultiValueMap.containsKey(uInfoV2.getBindingRoom())
                    && !uInfoV2.getUserType().equals(OwnerConstant.ROLE_MANAGER_TYPE)) {
                uInfoV2.setDevicesList(acLinkedMultiValueMap.getValues(uInfoV2.getBindingRoom()));
            } else if (uInfoV2.getUserType().equals(OwnerConstant.ROLE_MANAGER_TYPE)) {
                String where = "where 1=1 and comm_code = '" + uInfoV2.getCommCode() + "'";
                List<TblBuildingDimBo> bos = IBuildingService.findTblBuildingDimByWhere(where);
                List<TblCommDimBo> comms = ICommService.findTblCommDimByWhere(where);
                List<UserDevice> devicesList = new ArrayList<UserDevice>();
                UserDevice devices;
                for (TblBuildingDimBo tblBuildingDimBo : bos) {
                    String areaName = tblBuildingDimBo.getAreaName();
                    String buildingName = tblBuildingDimBo.getBuildingName();
                    int devNumber = tblBuildingDimBo.getDevNumber();

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append(uInfoV2.getCommCode());
                    if (areaName.length() == 1) {
                        stringBuilder.append("0").append(areaName);
                    } else {
                        stringBuilder.append(areaName);
                    }

                    if (buildingName.length() == 1) {
                        stringBuilder.append("0").append(buildingName);
                    } else {
                        stringBuilder.append(buildingName);
                    }

                    for (int i = 0; i < devNumber; i++) {
                        String devNum = String.valueOf(i + 1);
                        String sipNum = stringBuilder.toString() + "000" + devNum;
                        devicesList.add(new UserDevice(sipNum, AccountsUtils.getUnitInfo(sipNum) + ":门口机-" + devNum));
                    }
                }

                int gateDevNum = comms.get(0).getGateDevNum();

                if (gateDevNum > 0) {
                    for (int i = 0; i < gateDevNum; i++) {
                        devices = new UserDevice();
                        String sipNum = uInfoV2.getCommCode() + "0000000" + numberToEnglish[i];
                        devices.setAccounts(sipNum);
                        devices.setDisplayName(commUtil.getGateDevAliasName(sipNum, comms.get(0).getGateDevAliasName()));
                        devicesList.add(devices);
                    }
                }
                uInfoV2.setDevicesList(devicesList);
            }
        }

		/*
         * userInfoList.setUnlockList(unlockList);
		 * userInfoList.setUserInfoList(uList);
		 */
        return new JsonRespData("getAllBindingList", 1, uList);
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("visitorAuthorization")
    @ResponseBody
    JsonRespData visitorAuthorization(long timeStart, long timeEnd, String username, String RoomInfoNum) {
        int randomPwd = 0;
        List<TblSipAcountBindings> list = ISipAcountService.genDefaultSipUnlockMonitorBindingList(username,
                RoomInfoNum);
        if (list == null || list.size() == 0)
            return new JsonRespData("visitorAuthorization", -1, "您不是该房号业主！");
        ListOperations<String, String> listOperations = stringTemplate.opsForList();
        randomPwd = (int) (Math.random() * 1000000);
        for (TblSipAcountBindings binding : list) {
            String key = "visitorAuth:" + binding.getBinding() + ":" + randomPwd;
            listOperations.rightPush(key, timeStart + "-" + timeEnd + "-" + AccountsUtils.getFloor(RoomInfoNum) + AccountsUtils.getRoom(RoomInfoNum));
            stringTemplate.expireAt(key, DateUtil.getdateReturnDate(7));
        }

        return new JsonRespData("visitorAuthorization", 1, randomPwd);
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("visitorPasswordCheck")
    @ResponseBody
    JsonRespData visitorPasswordCheck(String devNumber, String password) {
        String key = "visitorAuth:" + devNumber + ":" + password;

        ListOperations listOperations = stringTemplate.opsForList();
        List<String> timeList = listOperations.range(key, 0, -1);
        if (timeList == null || timeList.size() <= 0)
            return new JsonRespData("visitorPasswordCheck", -1, "密码不存在");

        Long now = DateUtil.getTimeStampsNowFmtSec();
        for (String time : timeList) {
            String[] times = time.split("-");
            long startTime;
            long endTime;
            String room = null;
            if (times.length == 2) {
                startTime = Long.valueOf(times[0]);
                endTime = Long.valueOf(times[1]);
            } else if (times.length == 3) {
                startTime = Long.valueOf(times[0]);
                endTime = Long.valueOf(times[1]);
                room = times[2];
            } else {
                return new JsonRespData("visitorPasswordCheck", -1, "密码匹配错误！");
            }
            if (now > startTime && now < endTime)
                return new JsonRespData("visitorPasswordCheck", 1, room);
        }
        return new JsonRespData("visitorPasswordCheck", -1, "不在授权时间内！");
    }

    /**
     * 客户端同步当前通知
     *
     * @param type      通知类型
     * @param adviceNum 设备编号
     * @param date      // 用于增量更新的对比时间
     * @return
     * @throws Exception
     */
    @RequestMapping("anon/synNotice")
    @ResponseBody
    JsonRespData synNotice(String type, String adviceNum, String date) throws Exception {
        List<Map<String, Object>> list = noticeDimService.queryResourceList(type, adviceNum, date);
        return new JsonRespData("visitorPasswordCheck", 1, list);
    }

    /**
     * 客户端申请被拒绝或者还未通过时，可以调用此接口撤销申请
     *
     * @param roomInfoNum
     * @param ownerMob
     * @return
     */
    @RequestMapping({"removeOwner"})
    @ResponseBody
    JsonRespData removeOwner(String roomInfoNum, String ownerMob) throws Exception {
        List<TblOwnerDimBo> list = IOwnerService.findTblOwnerDimByWhere("where roomInfoNum = '" + roomInfoNum + "' and owner_mob = '" + ownerMob + "'");
        if (list != null && list.size() != 0) {
            for (TblOwnerDimBo owner : list) {
                if (owner.getApplyType() != OwnerConstant.OWNER_TYPE_APPLYING && owner.getApplyType() != OwnerConstant.OWNER_TYPE_REJECTED)
                    return new JsonRespData("removeOwner", -1, "只能删除申请中状态的业主信息!");
                else
                    IOwnerService.removeDim(owner.getOwnerCode());
            }

            return new JsonRespData("removeOwner", 1, "删除成功!");
        }

        return new JsonRespData("removeOwner", -1, "未找到该条记录!");
    }

    /**
     * 通过OwnerCode删除Owner别墅需要在机器上删除业主
     *
     * @param ownerCode 业主ID
     * @return
     * @throws Exception
     */
    @RequestMapping({"removeOwnerByOwnerCode"})
    @ResponseBody
    JsonRespData removeOwnerByOwnerCode(String ownerCode) throws Exception {
        TblOwnerDimBo ownerDimBo = IOwnerService.findTblOwnerDimById(ownerCode);
        if (ownerDimBo == null) {
            return new JsonRespData("deleteOwner", -1, "业主不存在！");
        }
        ISipAcountService.removeSipBinding(ownerDimBo.getOwnerMob(), ownerDimBo.getRoomInfoNum());
        IOwnerService.removeDim(ownerCode);
        return new JsonRespData("removeOwner", 1, "删除成功!");
    }

    @RequestMapping({"getUpdatedData", "anon/getUpdatedData"})
    @ResponseBody
    JsonRespData getUpdatedData(@RequestBody(required = false) DataUpdateParam params) throws Exception {
        Map datas = new HashMap<>();
        for (String module : params.getModules().keySet()) {
            if (StringUtils.isNotEmpty(params.getForce()) && StringUtils.isEmpty(params.getModules().get(module).get("force")))
                params.getModules().get(module).put("force", params.getForce());
            DataUpdateObject obj = dataUpdateService.getUserUpdateDataForModule(params.getUsername(), params.getOwnerCode(), module, params.getLabel(), params.getModules().get(module));
            if (obj == null)
                continue;
            datas.put(module, obj.getDatalist());
            if (obj.getSize() > 0)
                datas.put(module.toLowerCase() + "_size", obj.getSize());

        }

        return new JsonRespData("", 1, datas);
    }

    /**
     * 获取业主列表
     *
     * @param commCode
     * @param building
     * @param unit
     * @param floor
     * @param roomNum
     * @return
     * @throws Exception
     */
    @RequestMapping("getOwnerInfos")
    @ResponseBody
    public JsonRespData getOwnerInfos(String commCode, String building, String unit, String floor, String roomNum) throws Exception {
        List<TblOwnerDimBo> ownerDimBos = IOwnerService.findTblOwnerDimByWhere("where comm_code = '" + commCode +
                "' and area_code = '" + building +
                "' and building_code = '" + unit +
                "' and unit_code='" + floor +
                "' and room_code='" + roomNum + "'");
        return new JsonRespData("", 1, ownerDimBos);
    }

    /**
     * 保存人脸信息
     *
     * @param faceInfo
     * @return
     * @throws Exception
     */
    @RequestMapping("saveFace")
    @ResponseBody
    public JsonRespData saveFace(FaceInfo faceInfo) throws Exception {
        faceService.saveFaceInfo(faceInfo);
        return new JsonRespData("", 1, "");
    }

    /**
     * 通过业主code获取人脸信息
     *
     * @param ownerCode
     * @return
     * @throws Exception
     */
    @RequestMapping("getFaceInfo")
    @ResponseBody
    public JsonRespData getFaceInfo(String ownerCode) throws Exception {
        List<FaceInfo> faceInfos = faceService.getFaceInfosByWhere("where owner_code = '" + ownerCode + "'", true);
        if (faceInfos == null || faceInfos.size() <= 0) {
            return new JsonRespData("", -1, "没有人脸信息！");
        }
        return new JsonRespData("", 1, faceInfos.get(0));
    }

    /**
     * 注册成为业主
     *
     * @param ownerName
     * @param commCode
     * @param ownerMob
     * @param areaCode
     * @param buildingCode
     * @param roomCode
     * @return
     */
    @RequestMapping("registerOwner")
    @ResponseBody
    public JsonRespData registerOwner(String ownerName, String commCode, String ownerMob, String areaCode, String buildingCode, String roomCode, Long timeStamp) throws Exception {
        timeStamp = System.currentTimeMillis();
        JsonRespData jsonRespData = super.registerOwner(ownerName, commCode, ownerMob, areaCode, buildingCode, roomCode, timeStamp);

        //推送管理手机
        List<TblOwnerDimBo> ownerDimBos = IOwnerService.findTblOwnerDimByWhere("where comm_code = '" + commCode + "' and apply_type = '" + OwnerConstant.OWNER_TYPE_PROPERTY_MANAGER + "'");
        if (ownerDimBos != null && ownerDimBos.size() > 0) {
            for (TblOwnerDimBo ownerDimBo : ownerDimBos) {
                dataUpdateService.pushAndUpdate(timeStamp, OwnerDataUpdate.APPLY_OWNER, ownerDimBo.getOwnerMob(), true, true, "", "");
            }
        }

        //管理机推送
        TblCommDimBo commDimBo = ICommService.findTblCommDimByCommCode(commCode);
        int gateManageNum = commDimBo.getManageDevNum();
        if (gateManageNum > 0) {
            for (int i = 1; i < gateManageNum + 1; i++) {
                String sipNum = commCode + "0000000" + i;
                dataUpdateService.pushAndUpdate(timeStamp, OwnerDataUpdate.APPLY_OWNER, sipNum, true, false, "", "");
            }
        }
        return jsonRespData;
    }


    /**
     * 别墅添加业主
     */
    @RequestMapping("villaAddOwner")
    @ResponseBody
    public JsonRespData villaAddOwner(String ownerName, String commCode, String ownerMob, String building, String unit, String floorCode, String roomCode) throws Exception {
        return addOwner(ownerName, commCode, ownerMob, building, unit, floorCode, roomCode, OwnerConstant.OWNER_TYPE_VILLA);
    }

    private JsonRespData addOwner(String ownerName,
                                  String commCode,
                                  String ownerMob,
                                  String building,
                                  String unit,
                                  String floorCode,
                                  String roomCode,
                                  int ownerType) throws Exception {
        TblOwnerDimBo ownerDimBo = new TblOwnerDimBo();
        ownerDimBo.setCommCode(commCode);
        if (!StringUtils.isEmpty(ownerName)) {
            ownerDimBo.setOwnerName(ownerName);
        } else {
            return new JsonRespData("putOwner", -1, "业主名称必须填写！");
        }
        if (!StringUtils.isEmpty(ownerMob)) {
            ownerDimBo.setOwnerMob(ownerMob);
        } else {
            return new JsonRespData("putOwner", -1, "业主手机必须填写！");
        }
        List<TblBuildingDimBo> buildingDimBos;
        if (isBuildingInfo(building)) {
            buildingDimBos = buildingDimService.findTblBuildingDimByWhere("where comm_code = '" + commCode + "' and area_name='" + dealBuildingData(building) + "'");
            if (buildingDimBos != null && buildingDimBos.size() > 0) {
                ownerDimBo.setAreaCode(AccountsUtils.appendZeroBuilding(buildingDimBos.get(0).getAreaName()));
                ownerDimBo.setCommName(buildingDimBos.get(0).getCommName());
            } else {
                return new JsonRespData("putOwner", -1, "没有该楼栋！");
            }
        } else {
            return new JsonRespData("putOwner", -1, "栋号必须为2为数字！");
        }

        if (isBuildingInfo(unit)) {
            ownerDimBo.setBuildingCode(unit);
        } else {
            return new JsonRespData("putOwner", -1, "单元号必须为2为数字！");
        }
        if (isBuildingInfo(floorCode)) {
            ownerDimBo.setUnitCode(floorCode);
        } else {
            return new JsonRespData("putOwner", -1, "楼号必须为2为数字！");
        }
        if (isBuildingInfo(roomCode)) {
            ownerDimBo.setRoomId(roomCode);
        } else {
            return new JsonRespData("putOwner", -1, "房号必须为2为数字！");
        }

        ownerDimBo.setApplyType(ownerType);
        StringBuilder roomInfoNum = new StringBuilder();
        String roomInfo = "[" + ownerDimBo.getCommName() + "]";
        //新的小区加入别名
        if (buildingDimBos.size() > 0) {
            roomInfo += " " + buildingDimBos.get(0).getAreaAliasName() + " ";
        } else {
            roomInfo += " " + ownerDimBo.getAreaCode() + "栋 ";
        }
        roomInfo += ownerDimBo.getBuildingCode() +
                "单元 " +
                ownerDimBo.getUnitCode() +
                "楼 " +
                ownerDimBo.getRoomId() +
                "房";
        roomInfoNum.append(ownerDimBo.getCommCode())
                .append(AccountsUtils.getCompactAeraCode(ownerDimBo.getAreaCode()))
                .append(ownerDimBo.getBuildingCode())
                .append(ownerDimBo.getUnitCode())
                .append(ownerDimBo.getRoomId());

        ownerDimBo.setRoomInfo(roomInfo);
        ownerDimBo.setRoomInfoNum(roomInfoNum.toString());
        ownerDimBo.setLastModify(DateUtil.getTimeNowFmtSec());
        ownerDimBo.setLastModifyTimeStamp(DateUtil.getTimeStampsNowFmtSec());

        /* 判断申请的业主是否已申请过 */
        String checkResult = IOwnerService.checkFormOwnerLegal(ownerDimBo);
        if (checkResult != null) {
            return new JsonRespData("putOwner", -1, checkResult);
        }
        /* 未申请过的话就添加业主sip账号 */
        String accountId = ISipAcountService.addSipAccount(ownerDimBo.getOwnerMob(), Global.DEFAULT_USER_PWD, "mobile", false);
        /* 为该sip账号添加默认的设备绑定 */
        ISipAcountService.addSipBinding(ownerDimBo.getOwnerMob(), roomInfoNum.toString(), Global.BINDING_TYPE_INDOOR, 0);
        ownerDimBo.setSipAcountId(accountId);
        ownerDimBo.setOwnerCode(GetId.randomID());
        IOwnerService.save(ownerDimBo);
        return new JsonRespData("putOwner", 1, "添加成功");
    }

    private boolean isBuildingInfo(String bInfo) {
        return bInfo != null && ObjectUtils.isNumeric(bInfo) && bInfo.length() == 2;
    }

    private String dealBuildingData(String data) {
        return String.valueOf(Integer.valueOf(data));
    }

    /**
     * 更新用户推送token
     * @param username
     * @param vendor
     * @param pushToken
     * @param force
     * @return
     * @throws Exception
     */
    @RequestMapping("updateUserDeviceToken")
    @ResponseBody
    JsonRespData updateUserDeviceToken(String username,String vendor,String pushToken, boolean force) throws Exception{
        TblSipAcountDimBo sipAcountDimBo = ITblSipAcountDimService.getSipAccountByUser(username);
        if(com.jhws.util.StringUtils.isNotEmpty(sipAcountDimBo.getPushToken()) && !force){
            return new JsonRespData("",-1,"检测到您当前呼叫绑定的不是此设备，确认要绑定么?之前的设备将无法收到呼叫推送");
        }else{
            sipAcountDimBo.setVendor(vendor);
            sipAcountDimBo.setPushToken(pushToken);
            ITblSipAcountDimService.save(sipAcountDimBo);
            return new JsonRespData("",1,"");
        }
    }
}
